"""
@name : ip-test
@author : maxueyan
@projectname: sanchuang
"""

import subprocess
import IPy
try:
    ip = input("请输入网段：")
    ips = IPy.IP(ip)
    with open("ip_test.txt","w+",encoding="UTF-8") as file1:
        for i in ips:
            command = "ping -c 1 -w 1 {ip}"
            t = subprocess.run(command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
            if t.returncode == 0:
                print(f"{i}已被使用")
                file1.write(str(i)+"已被使用\n")
            else:
                print(f"{i}未被使用")
                file1.write(str(i)+"未被使用\n")
except:
    print("你的输入方式错误")



